package com.yeban.javase.day06.test02_clone.clone1;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/14
 */
public class Test {

    public static void main(String[] args) throws CloneNotSupportedException {

        // 创建一个Car对象car1
        Car car1 = new Car("特斯拉",320000);
        Car car2 = new Car("特斯拉",310000);

        // 创建了一个Person对象person1
        Person person1 = new Person("张三",19,car1);
        System.out.println(person1);

        // clone这个person1
        Person clonePerson1 = (Person)person1.clone();
        System.out.println(clonePerson1);

        // 修改克隆的对象，观察原对象的值是否被改变
        car1.setPrice(300000);
        System.out.println();
        System.out.println(person1);
        System.out.println(clonePerson1);

        // 修改克隆对象中的Car
        System.out.println();
        clonePerson1.setCar(car2);
        System.out.println(person1);
        System.out.println(clonePerson1);

    }

}
